From 128585147f697173ba807cb40089f5dad209457b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 6 Jul 2008 05:34:03 +0000 Subject: [PATCH] =?utf8?q?Bug=20541645=20=E2=80=93=20gtkfilechooserdefault?= =?utf8?q?=20segfaults=20when=20bookmark=20does=20not?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2008-07-06 Matthias Clasen Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not contain :// * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file): Be more robust. Reported by Jelte van der Hoek svn path=/trunk/; revision=20787 --- ChangeLog | 8 ++++++ gtk/gtkfilechooserdefault.c | 57 ++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 943ccc1c11..66b64b28fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-07-06 Matthias Clasen + + Bug 541645 – gtkfilechooserdefault segfaults when bookmark does not + contain :// + + * gtk/gtkfilechooserdefault.c (_gtk_file_chooser_label_for_file): + Be more robust. Reported by Jelte van der Hoek + 2008-07-06 Matthias Clasen Bug 540917 – deprecate pack_start_defaults() diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 458bdee71a..c101492ed4 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -1621,37 +1621,42 @@ _gtk_file_chooser_label_for_file (GFile *file) uri = g_file_get_uri (file); start = strstr (uri, "://"); - start += 3; - path = strchr (start, '/'); - - if (path) - end = path; - else + if (start) { - end = uri + strlen (uri); - path = "/"; - } + start += 3; + path = strchr (start, '/'); + if (path) + end = path; + else + { + end = uri + strlen (uri); + path = "/"; + } - /* strip username */ - p = strchr (start, '@'); - if (p && p < end) - { - start = p + 1; - } + /* strip username */ + p = strchr (start, '@'); + if (p && p < end) + start = p + 1; - p = strchr (start, ':'); - if (p && p < end) - end = p; + p = strchr (start, ':'); + if (p && p < end) + end = p; - host = g_strndup (start, end - start); - - /* Translators: the first string is a path and the second string - * is a hostname. Nautilus and the panel contain the same string - * to translate. - */ - label = g_strdup_printf (_("%1$s on %2$s"), path, host); + host = g_strndup (start, end - start); + + /* Translators: the first string is a path and the second string + * is a hostname. Nautilus and the panel contain the same string + * to translate. + */ + label = g_strdup_printf (_("%1$s on %2$s"), path, host); + + g_free (host); + } + else + { + label = g_strdup (uri); + } - g_free (host); g_free (uri); return label; -- 2.30.2